package server.core;

import java.util.HashMap;
import java.util.Map;

/**
 * The Managers class defines static methods for interacting with a global map
 * of <String, ProblemManager> pairs that allows for retrieving specific
 * {@link ProblemManager} implementations on the basis of the type of the
 * problem.
 * 
 * @author Clayton Edward Taylor
 */
public class Managers {

	private static Map<String, ProblemManager> managers = new HashMap<String, ProblemManager>();

	/**
	 * Sets the {@link ProblemManager} for the given problem type.
	 * 
	 * @param type    - The name of the problem type
	 * @param manager - The ProblemManager that handles problems of that type
	 * @see             Managers
	 */
	public static synchronized void setManager(String type, ProblemManager manager) {

		managers.put(type, manager);
	}

	/**
	 * Removes the {@link ProblemManager} for the given problem type.
	 * 
	 * @param type - The name of the problem type
	 * @see          Managers
	 */
	public static synchronized void removeManager(String type) {

		managers.remove(type);
	}

	/**
	 * Gets the {@link ProblemManager} for the given problem type.
	 * 
	 * @param type - The name of the problem type
	 * @return       A ProblemManager if the type is in the map, or
	 *               <code>null</code> if it is not
	 * @see          Managers
	 */
	public static synchronized ProblemManager getManager(String type) {

		return managers.get(type);
	}
}
